const mysql = require('mysql2/promise')
const config = require('./config/database')

async function checkAuthorsColumns () {
  let connection
  try {
    connection = await mysql.createConnection({
      host: config.host,
      port: config.port,
      user: config.user,
      password: config.password,
      database: 'novel_platform'
    })

    console.log('检查authors表的列结构...')

    // 获取表结构
    const [columns] = await connection.execute(`
      SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT, COLUMN_COMMENT
      FROM INFORMATION_SCHEMA.COLUMNS 
      WHERE TABLE_SCHEMA = 'novel_platform' AND TABLE_NAME = 'authors'
      ORDER BY ORDINAL_POSITION
    `)

    console.log('\nauthors表的列:')
    columns.forEach(col => {
      console.log(
        `- ${col.COLUMN_NAME}: ${col.DATA_TYPE}${
          col.COLUMN_COMMENT ? ` (${col.COLUMN_COMMENT})` : ''
        }`
      )
    })

    // 查看一些数据
    const [rows] = await connection.execute('SELECT * FROM authors LIMIT 3')
    console.log('\nauthors表示例数据:')
    console.log(rows)
  } catch (error) {
    console.error('检查authors表失败:', error.message)
  } finally {
    if (connection) {
      await connection.end()
    }
  }
}

checkAuthorsColumns()
